package com.xxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxy.entity.Message;
import com.xxy.entity.dto.MessageQueryDTO;
import com.xxy.entity.vo.MessageVO;
import com.xxy.mapper.MessageMapper;
import com.xxy.result.PageResult;
import com.xxy.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements IMessageService {
    @Autowired
    private MessageMapper messageMapper;
    @Override
    public List<MessageVO> queryByFilter(MessageQueryDTO messageQueryDTO) {
        return messageMapper.queryByFilter(messageQueryDTO);
    }

    @Override
    public PageResult query(MessageQueryDTO messageQueryDTO) {
        Page<MessageVO> page = new Page<>(messageQueryDTO.getCurrent(), messageQueryDTO.getSize());
        IPage<MessageVO> resultPage = messageMapper.query(page, messageQueryDTO);
        List<MessageVO> records = resultPage.getRecords();
        long total = resultPage.getTotal();
        return new PageResult(total, records);
    }
}
